
# command line arguments
AddOption('--core', dest='core', default=False, action='store_true',help='build the core')
AddOption('--release', dest='release', default=False, action='store_true',help='Compile in release mode.')
AddOption('--test', dest='unittest', default=False, action='store_true',help='compile with unittests.')
AddOption('--pretty', dest='pretty', default=False, action='store_true',help='prettify compiler output.')
AddOption('--extern', dest='extern', default=False, action='store_true',help='build extern libs(like log.')

# binary files in a separate folder ------------------------------------
VariantDir('build', 'src', duplicate=0)

# phobos libs
stdLibs = ['phobos2', 'pthread', 'rt']

plop = Environment()
#print plop["DLINK"]


# kiwi.core ------------------------------------------------------------
libKiwiCoreSrc = Glob('src/kiwi/core/*.d') + ['src/extern/log/log.d']
print libKiwiCoreSrc
libKiwiCore = Environment()
libKiwiCore.Append( DPATH = ['src/', 'src/extern/log/'] )
#libKiwiCore.Append( LINK = "dmd" )
libKiwiCore.Library('lib/kiwiCore', libKiwiCoreSrc)
libKiwiCore.SharedLibrary('lib/kiwiCore', libKiwiCoreSrc)
if GetOption('debug') :
    libKiwiCore.AppendUnique( DFLAGS='-version=debug' )
if GetOption('unittest') :
    libKiwiCore.Append( DFLAGS='-unittest' )
    libKiwiCore.Program('test/core', SRC = libKiwiCoreSrc + 'test/core.d', LIBS = stdLibs)


# kiwi.dynamic ---------------------------------------------------------    
def buildKiwiDyn(): 
    libKiwiDynSrc = Glob('kiwi/dynamic/*.d')
    libKiwiDyn = Environment()
    libKiwiDyn.Library('lib/kiwiDyn', libKiwiDynSrc)
    libKiwiDyn.SharedLibrary('lib/kiwiDyn', libKiwiDynSrc)
    if GetOption('debug') :
        libKiwiDyn.AppendUnique( DFLAGS='-version=debug' )
    if GetOption('unittest') :
        libKiwiDyn.Append( DFLAGS='-unittest' )
        libKiwiCore.Program('test/dyn', SRC = libKiwiDynSrc + 'test/dyn.d', LIBS = stdLibs)


# program --------------------------------------------------------------
testEnv = Environment()
programLibs = ['kiwiCore'] + stdLibs
testEnv.Append( DFLAGS='-unittest' )
if not GetOption('release') :
    testEnv.AppendUnique( DFLAGS='-version=debug' )
testEnv.Append( BUILDPATH='build/' )
testEnv.Append( DPATH=['./build', 'src/extern/log/'] )
testEnv.Append( LIBPATH='./lib' )
testEnv.Program( 'build/testSuite', Split('test/core.d src/extern/log/log.d'), LIBS=programLibs)


#if GetOption('pretty'):
#    testEnv["DCOM"] = testEnv["DCOM"] + " 2>&1 | tr a-z A-Z"

